<div class="content-wrapper">
    <section class="content-header">
        <h1>{$cateInfo?'编辑':'新增'}分类</h1>
        <ol class="breadcrumb">
            <li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">系统配置</li>
            <li class="active"><a href="/admin/itemCate/cateList1">二级分类</a></li>
            <li class="active">{$cateInfo?'编辑':'新增'}分类</li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-header with-border">
            </div>
            <div class="box-body">
                <form class="form-horizontal" role="form" action="javascrip:;" method="post">
                    <input type="hidden" name="id" id="id" value="{$cateInfo.id}" />
                    <div class="form-group">
                        <label for="name" class="col-sm-3 control-label"> 名称 </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="名称" id="name" name="name" value="{$cateInfo.name}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="pid" class="col-sm-3 control-label"> 所属分类 </label>
                        <div class="col-sm-6">
                            <select class="form-control" id="pid" name="pid">
                                <option value="0">请选择</option>
                                <foreach name="p_cate" item="p">
                                    <option value="{$p.id}" <if condition="$p.id eq $cateInfo.pid ">selected</if>>{$p.name}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="is_enquiry" class="col-sm-3 control-label"> 是否询价 </label>
                        <div class="col-sm-6">
                            <select class="form-control" id="is_enquiry" name="is_enquiry">
                                <option value="0">请选择</option>
                                <option value="1" <if condition="$cateInfo.is_enquiry eq 1">selected</if>>询价</option>
                                <option value="2" <if condition="$cateInfo.is_enquiry eq 2">selected</if>>不询价</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="is_schedule" class="col-sm-3 control-label"> 是否排期 </label>
                        <div class="col-sm-6">
                            <select class="form-control" id="is_schedule" name="is_schedule">
                                <option value="0">请选择</option>
                                <option value="1" <if condition="$cateInfo.is_schedule eq 1">selected</if>>排期</option>
                                <option value="2" <if condition="$cateInfo.is_schedule eq 2">selected</if>>不排期</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="status" class="col-sm-3 control-label"> 状态 </label>
                        <div class="col-sm-6">
                            <select class="form-control" id="status" name="status">
                                <option value="1" <if condition="$cateInfo.status eq 1 ">selected</if>>正常</option>
                                <option value="-1" <if condition="$cateInfo.status eq -1 ">selected</if>>关闭</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="form-field-1" class="col-sm-3 control-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-info btn-sm save-btn">提交</button>
                            &nbsp;
                            <button type="reset" class="btn btn-sm">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>
<script type="application/javascript">
    //保存
    $(".save-btn").click(function(){
        var id = $("#id").val();
        var name = $.trim($("#name").val());
        var pid = $("#pid").val();
        var is_enquiry = $("#is_enquiry").val();
        var is_schedule = $("#is_schedule").val();
        var status = $("#status").val();

        if(name == '') {
            ArtDialogHlp.showInfo('提示', '请填写分类名');
            $("#name").focus();
            return false;
        }
        if(pid == 0 || pid== '') {
            ArtDialogHlp.showInfo('提示', '请选择一级分类');
            $("#pid").focus();
            return false;
        }
        if(is_enquiry == 0 || is_enquiry== '') {
            ArtDialogHlp.showInfo('提示', '请选择是否询价');
            $("#is_enquiry").focus();
            return false;
        }
        if(is_schedule == 0 || is_schedule== '') {
            ArtDialogHlp.showInfo('提示', '请选择是否排期');
            $("#is_schedule").focus();
            return false;
        }

        $.post('/admin/itemCate/ajaxSaveCate',
            {
                id : id,
                name :name,
                pid : pid,
                is_enquiry: is_enquiry,
                is_schedule: is_schedule,
                status : status
            }, function(data){
                if(data.Code == 999) {
                    ArtDialogHlp.showInfo('提示', '操作成功', function(){
                        window.location.href = '/admin/ItemCate/cateList2';
                    });
                } else {
                    ArtDialogHlp.showInfo('提示', data.Msg);
                }
            }, 'json');
    });
</script>